<?php 
namespace Api\Controller;
use Think\Controller;
use JPush\JPushClient;
class TestController extends Controller{
	public function test213(){
		for($i=100;$i<200;$i++){
	
			 
			M("shop")->execute("INSERT INTO `hui_shop` ( `shopAccount`, `shopPassword`, `shopName`, `province`, `district`, `city`, `address`, `desc`, `x`, `y`, `headImg`, `thumb`, `shopGrade`, `goodsGrade`, `orderNum`, `saleNum`, `goodsCommentNum`, `shopCommentNum`, `addTime`, `updateTime`, `isOn`, `lastLogin`, `lastIp`, `loginNum`, `shopType`, `allowCard`) VALUES ('atuo_shop".$i."', 'aaa', '洗衣店".$i."', '', '', '', '测试店铺地址', '测试店铺描述', '111.11', '222.22', '', '', '5', '2', '100', '100', '50', '50', '1402151400', '1423034736', '1', NULL, '', '0', '2', '1')");
	
		}
	}
	
	public function test456456(){
		$shop=M("shop")->where("shopType=1 and isOn = 1")->select();
		$model = M("goods");
		foreach ($shop as $aa){
                    $oil = array();
                    $shopData = array();
                    $shopData['shopID'] = $aa['shopID'];
                    $oil[] = array("name"=>'0#','price'=>$aa['oil0']);
                    $oil[] = array("name"=>'92#','price'=>$aa['oil92']);
                    $oil[] = array("name"=>'95#','price'=>$aa['oil95']);
                    
                    $shopData['oilPriceJson'] = json_encode($oil,JSON_UNESCAPED_UNICODE);
                    $shopData['addTime'] = time();
                    
                    dump(M("Shop")->save($shopData));
                    
                    if($aa['canuse'] == 1) {
                        
			$model->execute("INSERT INTO `hui_goods` (`shopID`, `goodsName`, `goodsSn`, `num`, `catID`, `goodsPrice`, `unit`, `marketPrice`, `headImg`, `thumb`, `desc`, `addTime`, `updateTime`, `isOn`, `isSale`, `autoSaleTime`, `autoUnSaleTime`)  VALUES (  '".$aa['shopID']."', '100元加油劵', '".rand(10000000,99999999)."', '100', '1', '100', '元/张', '0', '', '', '', '142545100', 0, '1', '1', 0, 0)");
			$model->execute("INSERT INTO `hui_goods` (`shopID`, `goodsName`, `goodsSn`, `num`, `catID`, `goodsPrice`, `unit`, `marketPrice`, `headImg`, `thumb`, `desc`, `addTime`, `updateTime`, `isOn`, `isSale`, `autoSaleTime`, `autoUnSaleTime`) VALUES (  '".$aa['shopID']."', '200元加油劵', '".rand(10000000,99999999)."', '100', '7', '200', '元/张', '0', '', '', '', '142545100', 0, '1', '1', 0, 0)");
			$model->execute("INSERT INTO `hui_goods` (`shopID`, `goodsName`, `goodsSn`, `num`, `catID`, `goodsPrice`, `unit`, `marketPrice`, `headImg`, `thumb`, `desc`, `addTime`, `updateTime`, `isOn`, `isSale`, `autoSaleTime`, `autoUnSaleTime`) VALUES (  '".$aa['shopID']."', '300元加油劵', '".rand(10000000,99999999)."', '100', '6', '300', '元/张', '0', '', '', '', '142545100', 0, '1', '1', 0, 0)");
                    }
                    dump($model->getLastSql());
		
		}
	}
	
	public function test789789(){
		$shop=M("shop")->where("shopType=1 and isOn = 1 and province='福建省'")->select();
		$model = M("goods");
		foreach ($shop as $aa){
			$model->execute("INSERT INTO `hui_goods` (`shopID`, `goodsName`, `goodsSn`, `num`, `limitNum`, `catID`, `goodsPrice`, `unit`, `marketPrice`, `headImg`, `thumb`, `desc`, `addTime`, `updateTime`, `isOn`, `isSale`, `autoSaleTime`, `autoUnSaleTime`)  VALUES (  '".$aa['shopID']."', '100元油券+（福建）', '".rand(10000000,99999999)."', '-1', '-1', '44', '95', '元/张', '0', '', '', '', '".time()."', 0, '1', '1', NULL, NULL)");
			$model->execute("INSERT INTO `hui_goods` (`shopID`, `goodsName`, `goodsSn`, `num`, `limitNum`, `catID`, `goodsPrice`, `unit`, `marketPrice`, `headImg`, `thumb`, `desc`, `addTime`, `updateTime`, `isOn`, `isSale`, `autoSaleTime`, `autoUnSaleTime`) VALUES (  '".$aa['shopID']."', '200元油券+（福建）', '".rand(10000000,99999999)."', '-1', '-1', '45', '190', '元/张', '0', '', '', '', '".time()."', 0, '1', '1', NULL, NULL)");
		}
	}
	
	public function test123123(){
		$model = M("goods");
		$model->execute("UPDATE hui_goods SET restNum=-1 WHERE goodsID>4525");
			
	}
	
        
	public function addGoodsForXichechang(){
		$shop=M("shop")->where("shopType=2 and isOn = 1")->select();
		
		foreach ($shop as $aa){
                    $shopData['shopID'] = $aa['shopID'];
                    $shopData['addTime'] = time();
                    $shopData['updateTime'] = time();
                    M("Shop")->save($shopData);
                    if($aa['canuse'] == 1) {
			M("goods")
                                ->execute("INSERT INTO `hui_goods` (`shopID`, `goodsName`, `goodsSn`, `num`, `catID`, `goodsPrice`, `unit`, `marketPrice`, `headImg`, `thumb`, `desc`, `addTime`, `updateTime`, `isOn`, `isSale`, `autoSaleTime`, `autoUnSaleTime`)  "
                                        . "VALUES (  '".$aa['shopID']."', '30元洗车券', '".rand(10000000,99999999)."', '-1', '14', '30', '元/张', '0', '', '', '', ".time().", 0, '1', '1', 0, 0)");
//			M("goods")
//                                ->execute("INSERT INTO `hui_goods` (`shopID`, `goodsName`, `goodsSn`, `num`, `catID`, `goodsPrice`, `unit`, `marketPrice`, `headImg`, `thumb`, `desc`, `addTime`, `updateTime`, `isOn`, `isSale`, `autoSaleTime`, `autoUnSaleTime`) "
//                                        . "VALUES (  '".$aa['shopID']."', '200元洗车券', '".rand(10000000,99999999)."', '100', '2', '200', '元/张', '0', '', '', '', ".time().", null, '1', '1', null, null)");
//            M("goods")
//                                ->execute("INSERT INTO `hui_goods` (`shopID`, `goodsName`, `goodsSn`, `num`, `catID`, `goodsPrice`, `unit`, `marketPrice`, `headImg`, `thumb`, `desc`, `addTime`, `updateTime`, `isOn`, `isSale`, `autoSaleTime`, `autoUnSaleTime`) "
//                                        . "VALUES (  '".$aa['shopID']."', '300元洗车券', '".rand(10000000,99999999)."', '100', '2', '300', '元/张', '0', '', '', '', ".time().", null, '1', '1', null, null)");
                    }
		}
	}

	public function test123(){
		
		$json=json_encode(array("result"=>"234"));
		$result=http_post_json("http://localhost:8009/api/test/testpost", $json);
		dump($result);
		exit;
	}
	
	public function testpost(){
		//dump($_POST);
		echo $GLOBALS['HTTP_RAW_POST_DATA'];
	}
	
	
	public function sms(){
		$signature=$this->getSignature();
		
		$send=array(
			"app"=>$signature,
			"mobileNum"=>18575020603
		);
		
		dump(json_encode($send));
		
		$result=http_post_json(C("API_GET_SMS_CODE"), json_encode($send));
		dump($result);
		
	}
	
	public function register(){
		$signature=$this->getSignature();
		
		$send=array(
				"app"=>$signature,
				"mobileNum"=>18575020603
				
		);
		
		dump(json_encode($send));
		
		$result=http_post_json(C("API_GET_ACCOUNT_CODE"), json_encode($send));
		dump($result);
	}
	
	public function test213123(){
		$signature=$this->getSignature();
	
		$send=array(
				"app"=>$signature,
				"mobileNum"=>18575020603,
				"accountCode"=>"135656",
				"paymentCodeMD5"=>md5("123456")
		);
	
		$result=http_post_json(C("API_SET_PAYMENTCODE"), json_encode($send));
	
		dump(json_encode($send));
	
		
		dump($result);
	}
	
	
	public function getSignature(){
		$data=array(
				"appId"=>C("appID"),
				"appKey"=>C("appKey"),
				"nonce"=>rand(10000000, 99999999),
				"timeStamp"=>time()
		);
		
		$sort=$data; 
		
		sort($sort,SORT_STRING);
		
		foreach ($sort as $a){
			$str.=$a;
		}
		//dump($data);
		$data['signature']=md5($str);
		
		//dump($data);
		//dump($str);
		//dump(md5($str));
		
		return $data;
	}
	
	/**
	 * 获取渠道接口签名
	 * @return array
	 */
	public function _getHuitongSignature(){
		$url = C("HUITONG_URL");
		$query = array(
				'appNo' => C("HUITONG_APPNO"),
				'service' => "trade.queryAllCoupons",
				'ver' => C("HUITONG_VER"),
				'format' => "json",
				'charset' => "utf-8",
				'lang' => $this->_lang
		);
		$url .= http_build_query($query);
	}
	
	public function test234234(){
		$data=array(
				"pan"=>6660718800405200131,
				"password"=>$this->__getEncryptPwd(631594),
		);
		
		$result=$this->_getHuitongTokenID($data['pan'], $data['password']);
		dump($result);
	}
	
	public function testdfngkdfngk(){
		$a=array(
				"modelID"=>4,
				"info"=>array(
						array(
								"descID"=>1,
								"children"=>array(
										array("descID"=>2,"grade"=>600),
										array("descID"=>3,"grade"=>0),
								),
						),
						array(
								"descID"=>4,
								"children"=>array(
										array("descID"=>5,"grade"=>900),
										array("descID"=>6,"grade"=>300),
										array("descID"=>4,"grade"=>0),
								),
						),
				)
			
		);
		
		
		$json=json_encode($a);
		dump(json_decode($json,true));
	}
	
	public function test12345345fdxgdf(){
		$result=http_post_json("https://api.jpush.cn/v3/push", '{"platform":"all","audience":"all","notification":{"alert":"Hi,JPush!"}}',array("Authorization:".base64_encode("161f1017deaf5dc1cba3e83d:bb3a91fe849af6cb1d754db9")));
		dump($result);
	}
	
	public function ddd33sd54s(){
		phpinfo();
	}
	
	public function test234(){
	    S(C("CACHE_MEM2"));
	    dump(S('test','11111'));
	    dump(S("test"));
	    
	 }
	 
	 public function test2341(){
	     S(C("CACHE_MEM"));
	     dump(S('test','11111'));
	     dump(S("test"));
	      
	 }
	 
	 public function testfjdgkdssfg(){
	 	//连接远程主机默认端口
	 	$m = new MongoClient();
	 	dump($m);
	 }
	
	 public function testf444jdgkdssfg(){
	 	phpinfo();
	 }
	
}
?>